package VISTA.ventanas;

import BD.Pagosproveedores;
import NEGOCIOS.ControlPagoProveedores;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import reportes.Modulos.ModuloReporteNoBD;

public class PagosDeProveedores extends javax.swing.JInternalFrame {

    
    public PagosDeProveedores() {
        initComponents();
        //Obtengo la fecha actual del sistema
        Date fechaSistema = new Date();
        SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
        //Aplico el formato que nesesito y la muestro en el campo fecha
        jtfFecha.setText(fecha.format(fechaSistema));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpContenedor = new javax.swing.JPanel();
        jpContenido = new javax.swing.JPanel();
        jlNombre = new javax.swing.JLabel();
        jtfNombre = new javax.swing.JTextField();
        jlFecha = new javax.swing.JLabel();
        jlRFC = new javax.swing.JLabel();
        jtfRFC = new javax.swing.JTextField();
        jbAgregar = new javax.swing.JButton();
        jbQuitar = new javax.swing.JButton();
        jlCantidad = new javax.swing.JLabel();
        jtfCantidad = new javax.swing.JTextField();
        jtfFecha = new javax.swing.JTextField();
        jspPagos = new javax.swing.JScrollPane();
        jtPagos = new javax.swing.JTable();
        jpAcciones = new javax.swing.JPanel();
        jlTotal = new javax.swing.JLabel();
        jbGuardar = new javax.swing.JButton();
        jbImprimir = new javax.swing.JButton();
        jbSalir = new javax.swing.JButton();
        jtfTotal = new javax.swing.JTextField();
        jlTitulo = new javax.swing.JLabel();

        setBackground(new java.awt.Color(153, 51, 0));
        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Pagos a Proveedores");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/dollar.png"))); // NOI18N

        jpContenedor.setBackground(new java.awt.Color(153, 51, 0));

        jpContenido.setBackground(new java.awt.Color(255, 255, 255));
        jpContenido.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jpContenidoComponentShown(evt);
            }
        });

        jlNombre.setBackground(new java.awt.Color(102, 102, 102));
        jlNombre.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jlNombre.setForeground(new java.awt.Color(51, 51, 51));
        jlNombre.setText("Nombre del proveedor:");

        jtfNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfNombreKeyTyped(evt);
            }
        });

        jlFecha.setBackground(new java.awt.Color(102, 102, 102));
        jlFecha.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jlFecha.setForeground(new java.awt.Color(51, 51, 51));
        jlFecha.setText("Fecha: ");

        jlRFC.setBackground(new java.awt.Color(102, 102, 102));
        jlRFC.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jlRFC.setForeground(new java.awt.Color(51, 51, 51));
        jlRFC.setText("RFC:");

        jtfRFC.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfRFCKeyTyped(evt);
            }
        });

        jbAgregar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbAgregar.setForeground(new java.awt.Color(51, 51, 51));
        jbAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/mas.png"))); // NOI18N
        jbAgregar.setText("Agregar");
        jbAgregar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbAgregarMouseClicked(evt);
            }
        });

        jbQuitar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbQuitar.setForeground(new java.awt.Color(51, 51, 51));
        jbQuitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/menos.png"))); // NOI18N
        jbQuitar.setText("Quitar");
        jbQuitar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbQuitar.setPreferredSize(new java.awt.Dimension(97, 41));
        jbQuitar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbQuitarMouseClicked(evt);
            }
        });

        jlCantidad.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jlCantidad.setForeground(new java.awt.Color(51, 51, 51));
        jlCantidad.setText("Cantidad:");

        jtfCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfCantidadKeyTyped(evt);
            }
        });

        jtfFecha.setEditable(false);

        javax.swing.GroupLayout jpContenidoLayout = new javax.swing.GroupLayout(jpContenido);
        jpContenido.setLayout(jpContenidoLayout);
        jpContenidoLayout.setHorizontalGroup(
            jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpContenidoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpContenidoLayout.createSequentialGroup()
                        .addComponent(jlFecha)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jpContenidoLayout.createSequentialGroup()
                        .addComponent(jlNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                        .addComponent(jlRFC, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpContenidoLayout.createSequentialGroup()
                        .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtfCantidad)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpContenidoLayout.createSequentialGroup()
                                .addComponent(jlCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jtfNombre, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfRFC, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpContenidoLayout.createSequentialGroup()
                                .addComponent(jbAgregar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        jpContenidoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbAgregar, jbQuitar});

        jpContenidoLayout.setVerticalGroup(
            jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpContenidoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlFecha)
                    .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlNombre)
                    .addComponent(jlRFC))
                .addGap(4, 4, 4)
                .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfRFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jlCantidad)
                .addGap(1, 1, 1)
                .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpContenidoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jspPagos.setBackground(new java.awt.Color(255, 255, 255));

        jtPagos.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jtPagos.setForeground(new java.awt.Color(51, 51, 51));
        jtPagos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Proveedor", "RFC", "Fecha", "Cantidad"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jspPagos.setViewportView(jtPagos);
        if (jtPagos.getColumnModel().getColumnCount() > 0) {
            jtPagos.getColumnModel().getColumn(1).setPreferredWidth(100);
            jtPagos.getColumnModel().getColumn(1).setMaxWidth(200);
            jtPagos.getColumnModel().getColumn(2).setPreferredWidth(100);
            jtPagos.getColumnModel().getColumn(2).setMaxWidth(200);
            jtPagos.getColumnModel().getColumn(3).setPreferredWidth(100);
            jtPagos.getColumnModel().getColumn(3).setMaxWidth(200);
        }

        jpAcciones.setBackground(new java.awt.Color(255, 255, 255));

        jlTotal.setBackground(new java.awt.Color(102, 102, 102));
        jlTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jlTotal.setForeground(new java.awt.Color(51, 51, 51));
        jlTotal.setText("Total:");

        jbGuardar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbGuardar.setForeground(new java.awt.Color(51, 51, 51));
        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/save.png"))); // NOI18N
        jbGuardar.setText("Guardar");
        jbGuardar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbGuardar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbGuardarMouseClicked(evt);
            }
        });

        jbImprimir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbImprimir.setForeground(new java.awt.Color(51, 51, 51));
        jbImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/printer.png"))); // NOI18N
        jbImprimir.setText("Imprimir");
        jbImprimir.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbImprimirActionPerformed(evt);
            }
        });

        jbSalir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbSalir.setForeground(new java.awt.Color(51, 51, 51));
        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/Cancel.png"))); // NOI18N
        jbSalir.setText("Salir");
        jbSalir.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbSalirMouseClicked(evt);
            }
        });

        jtfTotal.setEditable(false);
        jtfTotal.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jtfTotal.setForeground(new java.awt.Color(153, 51, 0));
        jtfTotal.setText("0");

        javax.swing.GroupLayout jpAccionesLayout = new javax.swing.GroupLayout(jpAcciones);
        jpAcciones.setLayout(jpAccionesLayout);
        jpAccionesLayout.setHorizontalGroup(
            jpAccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpAccionesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlTotal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14))
        );

        jpAccionesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbGuardar, jbImprimir, jbSalir});

        jpAccionesLayout.setVerticalGroup(
            jpAccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpAccionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpAccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfTotal))
                .addContainerGap())
        );

        jlTitulo.setBackground(new java.awt.Color(255, 204, 0));
        jlTitulo.setFont(new java.awt.Font("Brush Script MT", 3, 36)); // NOI18N
        jlTitulo.setText("  Pagos a Proveedores");
        jlTitulo.setOpaque(true);

        javax.swing.GroupLayout jpContenedorLayout = new javax.swing.GroupLayout(jpContenedor);
        jpContenedor.setLayout(jpContenedorLayout);
        jpContenedorLayout.setHorizontalGroup(
            jpContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jpContenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpContenido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jspPagos)
                    .addComponent(jpAcciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpContenedorLayout.setVerticalGroup(
            jpContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpContenedorLayout.createSequentialGroup()
                .addComponent(jlTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpContenido, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jspPagos, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpAcciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpContenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpContenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jpContenidoComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jpContenidoComponentShown
    }//GEN-LAST:event_jpContenidoComponentShown

    private void jtfNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfNombreKeyTyped
        if (jtfNombre.getText().length() > 39) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + ", como maximo, 40 digitos", "Cantidad de digitos exedido",
                    0);
        }
        char key = evt.getKeyChar();
        if ((key < 'a' || key > 'z') && (key < 'A' || key > 'Z') && key != 'á'
                && key != 'é' && key != 'í' && key != 'ó' && key != 'ú' && key != 'Á'
                && key != 'É' && key != 'Í' && key != 'Ó' && key != 'Ú'
                && key != '\b' && key != (char) KeyEvent.VK_SPACE) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + " letras.", "Numeros no permitidos",
                    0);
        }
    }//GEN-LAST:event_jtfNombreKeyTyped

    private void jtfRFCKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRFCKeyTyped
        if (jtfRFC.getText().length() > 19) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + ", como maximo, 20 digitos", "Cantidad de digitos exedido",
                    0);
        }
    }//GEN-LAST:event_jtfRFCKeyTyped

    private void jtfCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCantidadKeyTyped
        char key = evt.getKeyChar();
        if ((key < '0' || key > '9') && key != '\b' && key != (char) KeyEvent.VK_SPACE && key != '.') {
            evt.consume();
            JOptionPane.showMessageDialog(this, "Solo se permiten numeros en "
                    + "este campo", "Lestras no permitidas", 0);
        }
    }//GEN-LAST:event_jtfCantidadKeyTyped

    private boolean verificarCamposVacios() {
        if (jtfNombre.getText().isEmpty() || jtfRFC.getText().isEmpty()
                || jtfCantidad.getText().isEmpty()) {
            return false;
        } else {
            return true;
        }
    }

    private void limpiarCampos() {
        jtfNombre.setText("");
        jtfRFC.setText("");
        jtfCantidad.setText("");
    }

    private void generarTotal(Double totalPago) {
        //Genera el total de todos los pagos 
        Double total = Double.parseDouble(jtfTotal.getText());
        total += totalPago;
        jtfTotal.setText(total.toString());
    }

    private void jbAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbAgregarMouseClicked
        if (verificarCamposVacios() == true) {
            DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
            modelo.addRow(new String[]{jtfNombre.getText(), jtfRFC.getText(),
                jtfFecha.getText(), jtfCantidad.getText()});
            generarTotal(Double.parseDouble(jtfCantidad.getText()));
            limpiarCampos();
            jtfNombre.requestFocusInWindow();
        } else {
            JOptionPane.showMessageDialog(this, "Hay campos vacios, porfavor "
                    + "llene todos los campos", "Faltan datos", 0);
        }

    }//GEN-LAST:event_jbAgregarMouseClicked

    private void jbQuitarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbQuitarMouseClicked
        if (jtPagos.getSelectedRow() != -1) {
            DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
            Double total = Double.parseDouble(jtfTotal.getText());
            total -= Double.parseDouble(modelo.getValueAt(jtPagos.getSelectedRow(), 3).toString());
            jtfTotal.setText(total.toString());
            modelo.removeRow(jtPagos.getSelectedRow());
        } else {
            JOptionPane.showMessageDialog(this, "Es necesario seleccionar un "
                    + "pago para poder quitarlo.", "Seleccione un pago", 0);
        }
    }//GEN-LAST:event_jbQuitarMouseClicked

    private void jbSalirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSalirMouseClicked
        try {
            this.setClosed(true);
        } catch (Exception e) {
            this.dispose();
        }
    }//GEN-LAST:event_jbSalirMouseClicked

    private void jbGuardarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbGuardarMouseClicked
        //Obtengo y la hago usable la fecha de los pagos
        SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
        //Creo el objeto de control para interactuar con la DB   
        ControlPagoProveedores cpp = new ControlPagoProveedores();
        //Creo la lista nesesaria para agregar los campos
        DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
        //Compruevo que la tabla tenga registros
        if (modelo.getRowCount() < 1) {
            JOptionPane.showMessageDialog(this, "Debe agregar por lo menos un "
                    + "pago para poder guardar.", "Error al guardar", 0);
        } else {
            List<Pagosproveedores> pagos = new ArrayList<>();
            for (int i = 0; i < modelo.getRowCount(); i++) {
                Pagosproveedores proveedor = new Pagosproveedores();
                try {
                    //Generamos el nuevo objeto que se agregara a la lista
                    proveedor.setFecha(formatoFecha.parse(jtfFecha.getText()));
                    proveedor.setNombre(modelo.getValueAt(i, 0).toString());
                    proveedor.setRfc(modelo.getValueAt(i, 1).toString());
                    proveedor.setTotal(Integer.parseInt(modelo.getValueAt(i, 3).toString()));
                    //Agrego a la lista el pago generado
                    pagos.add(proveedor);
                } catch (ParseException ex) {
                    JOptionPane.showMessageDialog(this, "Error:" + "\n" + ex,
                            "Error al intentar guardar el pago", 0);
                }
            }
            try {
                //Guardo la lista de pagos
                cpp.agregarVariosPagosProveedores(pagos);
                //Si todo salio bien informo al usuario
                JOptionPane.showMessageDialog(this, "Pagos guardados "
                        + "exitosamente", "Guardado", 1);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error:" + "\n" + e,
                        "Error al intentar guardar los pagos", 0);
            }
        }
        //Llamo el metodo que borra el contenido de la tabla
        borrarContenidoTabla();
        //Regreso el valor original de total
        jtfTotal.setText("0");
    }//GEN-LAST:event_jbGuardarMouseClicked

    private void jbImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbImprimirActionPerformed
        ModuloReporteNoBD reporteNBD = new ModuloReporteNoBD(jtPagos, "Proveedores");
    }//GEN-LAST:event_jbImprimirActionPerformed

    private void borrarContenidoTabla() {
        //Obtengo el modelo
        DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
        //Borro las todas las rows
        while (modelo.getRowCount() > 0) {
            modelo.removeRow(0);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JButton jbImprimir;
    private javax.swing.JButton jbQuitar;
    private javax.swing.JButton jbSalir;
    private javax.swing.JLabel jlCantidad;
    private javax.swing.JLabel jlFecha;
    private javax.swing.JLabel jlNombre;
    private javax.swing.JLabel jlRFC;
    private javax.swing.JLabel jlTitulo;
    private javax.swing.JLabel jlTotal;
    private javax.swing.JPanel jpAcciones;
    private javax.swing.JPanel jpContenedor;
    private javax.swing.JPanel jpContenido;
    private javax.swing.JScrollPane jspPagos;
    private javax.swing.JTable jtPagos;
    private javax.swing.JTextField jtfCantidad;
    private javax.swing.JTextField jtfFecha;
    private javax.swing.JTextField jtfNombre;
    private javax.swing.JTextField jtfRFC;
    private javax.swing.JTextField jtfTotal;
    // End of variables declaration//GEN-END:variables
}
